﻿@using System.ComponentModel
@using System.ComponentModel.DataAnnotations

<MForm Model="_model" EnableI18n>
    <MTextField @bind-Value="_model.Name"
                Counter="10"
                Label="Name">
    </MTextField>
    <MTextField @bind-Value="_model.Email"
                Label="E-mail">
    </MTextField>
    <MSelect @bind-Value="_model.Item"
             Items="@_items"
             Label="Item"
             ItemText="u => u"
             ItemValue="u => u">
    </MSelect>
    <MCheckbox @bind-Value="_model.Agree"
               Label="Do you agree?">
    </MCheckbox>
    <MButton Type="submit">Submit</MButton>
</MForm>

@code {

    private class Model
    {
        [Display(Name = "enableI18n-demo.name")]
        [Required(ErrorMessage = "enableI18n-demo.required")]
        [MaxLength(10, ErrorMessage = "enableI18n-demo.maxlength-10")]
        public string? Name { get; set; }

        [Display(Name = "enableI18n-demo.email")]
        [Required(ErrorMessage = "enableI18n-demo.required")]
        [EmailAddress(ErrorMessage = "enableI18n-demo.invalid-email")]
        public string? Email { get; set; }

        [Display(Name = "enableI18n-demo.item")]
        [Required(ErrorMessage = "enableI18n-demo.required")]
        public string? Item { get; set; }

        [RegularExpression("True", ErrorMessage = "enableI18n-demo.required-agree")]
        public bool Agree { get; set; }
    }

    private Model _model = new();

    private List<string> _items = new()
    {
        "Item 1",
        "Item 2",
        "Item 3",
        "Item 4"
    };

}